import 'package:app_flutter/main.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

import 'area/detail.dart';
import 'company/detail.dart';
import 'package:app_flutter/host.dart';
import 'company/search.dart';
import 'listpages.dart';
import 'login.dart';
import 'msg_manager.dart';

class Routes {
  static Router router;
  static String rootPage = '/';
  static String login = '/login';
  static String listPage = '/listpage';
  static String msgManager = '/msgmanager';
  static String pageHost = '/pagehost';
  static String comSearch = '/comSearch';
  static String areaDetail = '/areaDetail';
  static String comDetail = '/comDetail';

  static var listHandler = Handler(
      handlerFunc: (BuildContext context, Map<String, List<String>> params) {
    String type = params["type"]?.first;
    String titleIndex = params["titleIndex"]?.first;
    String page = params["page"]?.first;
    return ListPage(type: type, titleIndex: titleIndex, page: page);
  });

  static var loginHandler = Handler(
      handlerFunc: (BuildContext context, Map<String, List<String>> params) {
    String pageIndex = params['pageIndex']?.first;
    return Login(
      pageIndex: pageIndex,
    );
  });

  static var msgManagerHandler = Handler(
      handlerFunc: (BuildContext context, Map<String, List<String>> params) {
    String pageIndex = params['pageIndex']?.first;
    return MessageManager(
      pageIndex: pageIndex,
    );
  });

  static var pageHostHandler = Handler(
      handlerFunc: (BuildContext context, Map<String, List<String>> params) {
    String hostTitle = params["hostTitle"]?.first;
    String pageType = params["pageType"]?.first;
    return PageHost(
      hostTitle: hostTitle,
      pageType: pageType,
    );
  });

  static var comSearchHandler = Handler(
      handlerFunc: (BuildContext context, Map<String, List<String>> params) {
    return ComSearch();
  });
  static var areaDetailHandler = Handler(
      handlerFunc: (BuildContext context, Map<String, List<String>> params) {
    return AreaDetail();
  });

  static var comDetailHandler = Handler(
      handlerFunc: (BuildContext context, Map<String, List<String>> params) {
    String inscode = params["inscode"]?.first;
    return DetailPage(inscode: inscode);
  });

  static void configureRoutes(Router router) {
    router.define(rootPage,
        handler: Handler(handlerFunc: (context, params) => PageRoot()));

    router.define(listPage, handler: listHandler);
    router.define(login, handler: loginHandler);
    router.define(msgManager, handler: msgManagerHandler);
    router.define(pageHost, handler: pageHostHandler);
    router.define(comSearch, handler: comSearchHandler);
    router.define(areaDetail, handler: areaDetailHandler);
    router.define(comDetail, handler: comDetailHandler);

    Routes.router = router;
  }
}
